#pragma once

#include <iostream>
#include <unordered_set>
#include <string>
#include <pthread.h>

namespace ns_user_manage
{
    class UserManage
    {
    public:
        UserManage()
        {
            pthread_mutex_init(&_lock, nullptr);
        }

        ~UserManage()
        {
            pthread_mutex_destroy(&_lock);
        }
        //当用户登录之后， 将登录的用户保存在map当中
        void AddUserToSet(int user_id, int flag = 0)
        {
            pthread_mutex_lock(&_lock);
            if (flag == 0)
                _user_set1.insert(user_id);
            else
                _user_set2.insert(user_id);
            pthread_mutex_unlock(&_lock);
        }
        void DelUserSet(int user_id, int flag = 0)
        {
            pthread_mutex_lock(&_lock);
            if (flag == 0)
                _user_set1.erase(user_id);
            else
                _user_set2.erase(user_id);
            pthread_mutex_unlock(&_lock);
        }

    private:
        std::unordered_set<int> _user_set1; // 管理员
        std::unordered_set<int> _user_set2; // 普通用户
        pthread_mutex_t _lock;
    };
}